﻿module DocumentFactory

open Dom
open BrowserJsEngine
open DocumentHost
open HtmlDom
open DocumentWindow
open HtmlDocument
open Uris

let createDocument (changeCallback:DomChangedCallback) (uri:HttpUrl) (loader:IResourceLoader) (host:IDocumentHost) = 
    let createWindow doc = DocumentWindow(doc, host) :> IWindow
    let doc = HTMLDocument(uri, loader, changeCallback, htmlElementFactory, createBrowserJsEngine, createWindow)
    let head = doc.createElement("head")
    let body = doc.createElement("body")
    let html = HTMLHtmlElement(doc, "html", Map.empty, head, body)
    do doc.appendChild(html) |> ignore
    doc

